<?php
defined( '_VALID_MOS' ) or die('<script>window.location.href="http://www.kinifurniture.com";</script>');
$adm_functions->is_admin_login();
$adm_menu='
<table width="100%" class="menubar" cellpadding="0" cellspacing="0" border="0">
	<tr>
		<td class="menudottedline" width="40%">
			<div class="pathway"><img src="assets/admin/'.$SITE_LOGO_ADMIN.'"/></div>	</td>
		<td class="menudottedline" align="right">
			<table cellpadding="0" cellspacing="0" border="0" id="toolbar">
				<tr valign="middle" align="center">
					<td>&nbsp;</td>
					<td>
					<a class="toolbar" href="javascript:kliksubmit();">
						<img src="show_files/save.png"  alt="Save" name="save" title="Save" align="middle" border="0" />				<br />Save</a>
					</td>
					<td>&nbsp;</td>
					<td>
						<a class="toolbar" href="admin.php?show=news_manager">
						<img src="show_files/cancel.png"  alt="Cancel" name="cancel" title="Cancel" align="middle" border="0" />				<br />Cancel</a>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<br />
';
if ($msg=='1')	$error_message='Success Add News Detail';

if($inp_title)
{
		if($_FILES['inp_upl_file']['name'])
		{
			$fileexists='N';
			$file_name=basename($_FILES['inp_upl_file']['name']);
			$ekstensi=substr($_FILES['inp_upl_file']['name'],-3);
			if ($ekstensi=='pdf')
//			echo "<script>alert('".$ekstensi."');</script>";
			{
				$qryname="select * from news where filename='$file_name'";
				$selectname=$dbh->query($qryname);
				while($sqlRowedit=mysql_fetch_object($selectname))
				{
					$fileexists='Y';
				}
				if ($fileexists=='Y') 
				{
					echo '<script>alert("The Filename is already exists, try another filename");</script>';
					$val_title=$inp_title;
					$val_content=$inp_content;
					$val_url=$inp_url;
					if ($inp_active=='Y') 
					{
						$val_select1='selected'; 
						$val_select2=''; 
					}
					else 
					{
						$val_select1=''; 
						$val_select2='selected'; 
					}
					if ($inp_target=='B') 
					{
						$val_select3='selected'; 
						$val_select4=''; 
					}
					else 
					{
						$val_select3=''; 
						$val_select4='selected'; 
					}
				}
				else
				{
					$uploaddir = 'files/';
					$uploadfile = $uploaddir . basename($_FILES['inp_upl_file']['name']);
					move_uploaded_file($_FILES['inp_upl_file']['tmp_name'], $uploadfile);
					$img_name=basename($_FILES['inp_upl_file']['name']);
				}
			} else echo '<script>alert("The File Extension must be PDF");</script>';
		} else $file_name='';

				if ($fileexists!='Y')
		{
	$tanggal=time();
	$tanggal=date("Y-m-d H:i:s",$tanggal);
	$dbh->query("insert into news (
		title, 
		filename,
		contents,
		url,
		status,
		target,
		entrydate,
		news_type
		) values (
		'$inp_title', 
		'$file_name', 
		'$inp_content',
		'$inp_url',
		'$inp_active',
		'$inp_target',
		'$tanggal',
		'N'
		)");	
	echo '<script>alert("Added New News");</script>';
	echo '<script>window.location.href="admin.php?show=news_manager";</script>';
		}

}

?>